package com.julu.o2o.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式
 * @author yangtonggan
 * @date 2016-5-23
 */
public class RegexUtil {
	/**
	 * 获取匹配的字符串
	 * @param str
	 * @param patt
	 * @return
	 */
	public static String match(String str,String patt){
		try{
			 String pattern = patt;
			 Pattern r = Pattern.compile(pattern);
			 Matcher m = r.matcher(str);
			 if(m.find()){
				 String value = m.group();
				 return value;
			 }
		}catch(Exception e){
			throw new RuntimeException(e);
		}
		return null;
	}
	
	public static boolean isMatch(String str,String patt){
		try{
			 String pattern = patt;
			 Pattern r = Pattern.compile(pattern);
			 Matcher m = r.matcher(str);
			 return m.matches();			 
		}catch(Exception e){
			throw new RuntimeException(e);
		}
		
	}
	public static boolean notMatch(String str,String patt){
		return !isMatch(str,patt);
	}
	public static void main(String[] args){
		boolean sbc = isMatch("[\"0\",\"2\"]","\\[.+\\]");
		System.out.println(sbc);
	}
}
